<template>
	<view class="uni-popup-dialog">
		<view class="uni-dialog-title">
			<text class="v-text f38" style="color: #000;">选择</text>
		</view>

		<view v-if="tagid==0" class="p2 f-d a-c j-c  " style="background-color: #fff;">
			<input class="p1 f-d a-c j-c by1 pr2 f26" type="text" v-model="tagname" placeholder="添加标签"
				style="width: 350rpx;border: solid 2rpx #DCDCDC;background-color: #DCDCDC;height: 60rpx;" />
			<view @click="on_add" class="by1    f-d a-c j-c ml3"
				style="background-color: #FF375B;width: 120rpx;height: 60rpx;">
				<text class="f26 cff">添加</text>
			</view>
		</view>
		<view class="uni-dialog-title" v-if="tagid==0">


			<scroll-view scroll-y="true" style="height: 600rpx;padding-right: 20rpx;padding-left: 20rpx;width: 540rpx;">
				<view class="f-d j-b a-c pr2 pl2 pb2" v-for="(vo,index) in taglist">
					<view class="">
						<text class="f28 cred">{{vo.name}}</text>
					</view>
					<view @click="on_xz(vo.tag_id)" class="f-d a-c j-c"
						style="height: 60rpx;border: solid 2rpx #F33E35;border-radius: 60rpx;padding-right: 40rpx;padding-left: 40rpx;">
						<text class="f28" style="color: #F33E35;">选择</text>
					</view>

				</view>
			</scroll-view>

		</view>

		<view class="uni-dialog-title" v-if="tagid==1">

			<scroll-view scroll-y="true" style="height: 600rpx;padding-right: 20rpx;padding-left: 20rpx;width: 540rpx;">
				<view class="f-d j-b a-c pr2 pl2 pb2" v-for="(vo,index) in users_list">
					<view class="f-d a-c">
						<image :src="vo.face" style="height: 80rpx;width: 80rpx;"></image>
						<text class="f28 cred ml2">{{vo.nickname}}</text>
					</view>
					<view @click="on_xz1(vo.uid)" class="f-d a-c j-c"
						style="height: 60rpx;border: solid 2rpx #F33E35;border-radius: 60rpx;padding-right: 40rpx;padding-left: 40rpx;">
						<text class="f28" style="color: #F33E35;">选择</text>
					</view>

				</view>
			</scroll-view>

		</view>


		<view class="" style="height: 30rpx;">

		</view>


		<view class="uni-dialog-button-group">

			<view class="uni-dialog-button uni-border-left" @click="close">
				<text class="uni-dialog-button-text uni-button-color">关闭</text>
			</view>

		</view>

	</view>
</template>

<script>
	import popup from '../uni-popup/popup.js'
	import $H from '@/common/banmi/request.js';
	import {
		initVueI18n
	} from '@dcloudio/uni-i18n'
	import messages from '../uni-popup/i18n/index.js'
	const {
		t
	} = initVueI18n(messages)
	/**
	 * PopUp 弹出层-对话框样式
	 * @description 弹出层-对话框样式
	 * @tutorial https://ext.dcloud.net.cn/plugin?id=329
	 * @property {String} value input 模式下的默认值
	 * @property {String} placeholder input 模式下输入提示
	 * @property {String} type = [success|warning|info|error] 主题样式
	 *  @value success 成功
	 * 	@value warning 提示
	 * 	@value info 消息
	 * 	@value error 错误
	 * @property {String} mode = [base|input] 模式、
	 * 	@value base 基础对话框
	 * 	@value input 可输入对话框
	 * @property {String} content 对话框内容
	 * @property {Boolean} beforeClose 是否拦截取消事件
	 * @event {Function} confirm 点击确认按钮触发
	 * @event {Function} close 点击取消按钮触发
	 */

	export default {
		name: "uniPopupDialog",
		mixins: [popup],
		emits: ['confirm', 'close'],
		props: {
			issousuo: {
				type: String,
				default () {
					return '';
				}
			},
			tagid: {
				type: [String, Number],
				default: ''
			},
			value: {
				type: [String, Number],
				default: ''
			},
			sm: {
				type: [String, Number],
				default: ''
			},
			taglist: {
				type: Array,
				default () {
					return [];
				}
			},
			users_list: {
				type: Array,
				default () {
					return [];
				}
			},
			li: {
				type: Array,
				default () {
					return [];
				}
			},
			isvip: {
				type: [String, Number],
				default: ''
			},
			placeholder: {
				type: [String, Number],
				default: ''
			},
			post_id: {
				type: [String, Number],
				default: ''
			},
			type: {
				type: String,
				default: 'error'
			},
			mode: {
				type: String,
				default: 'base'
			},
			title: {
				type: String,
				default: ''
			},
			content: {
				type: String,
				default: ''
			},
			beforeClose: {
				type: Boolean,
				default: false
			},
			cancelText: {
				type: String,
				default: ''
			},
			cldid: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				dialogType: 'error',
				focus: false,
				val: "",
				tabidnex: 1,
				zd_price: 0,
				tagname: ''
			}
		},
		computed: {
			okText() {
				return this.confirmText || t("uni-popup.ok")
			},
			closeText() {
				return this.cancelText || t("uni-popup.cancel")
			},
			placeholderText() {
				return this.placeholder || t("uni-popup.placeholder")
			},
			titleText() {
				return this.title || t("uni-popup.title")
			}
		},
		watch: {
			type(val) {
				this.dialogType = val
			},
			mode(val) {
				if (val === 'input') {
					this.dialogType = 'info'
				}
			},
			value(val) {
				this.val = val
			}
		},
		created() {


			// 对话框遮罩不可点击
			this.popup.disableMask()
			// this.popup.closeMask()
			if (this.mode === 'input') {
				this.dialogType = 'info'
				this.val = this.value
			} else {
				this.dialogType = this.type
			}
		},
		mounted() {
			this.focus = true
		},
		methods: {
			on_add() {
				if (!this.tagname) {
					uni.showToast({
						title: '请输入标签'
					})
					return
				}
				var that = this;
				const user_id = uni.getStorageSync('user_id');
				const token = uni.getStorageSync('token');
				let requestParams = {
					user_id: user_id,
					token: token,
					tagname: this.tagname,
				};
				$H.post('/index.php/index/Bhou/pdd_tag_add', {
					token: true,
					datalist: requestParams
				}).then(ret => {

					if (ret.data.status == 200) {
						this.on_xz(ret.data.data.id)
					}

				})
			},
			on_xz(tag_id) {
				console.log("tag_id: " + JSON.stringify(tag_id));
				var that = this;
				const user_id = uni.getStorageSync('user_id');
				const token = uni.getStorageSync('token');
				let requestParams = {
					user_id: user_id,
					token: token,
					tag_id: tag_id,
					post_id: this.post_id
				};
				$H.post('/index.php/index/Bhou/pdd_tag_x', {
					token: true,
					datalist: requestParams
				}).then(ret => {
					this.popup.close()
					uni.showToast({
						title: ret.data.msg
					})
				})


			},
			on_xz1(uid) {
				var that = this;
				const user_id = uni.getStorageSync('user_id');
				const token = uni.getStorageSync('token');
				let requestParams = {
					user_id: user_id,
					token: token,
					uid: uid,
					post_id: this.post_id
				};
				$H.post('/index.php/index/Bhou/pdd_tag_uid', {
					token: true,
					datalist: requestParams
				}).then(ret => {
					this.popup.close()
					uni.showToast({
						title: ret.data.msg
					})
				})
			},
			onplay() {
				this.$emit('on_xuanze', this.cldid);
				this.popup.close()

			},
			xz1(id) {

				this.$emit('on_xuanze', id);
			},
			/**
			 * 点击确认按钮
			 */
			onOk() {
				if (this.mode === 'input') {
					this.$emit('confirm', this.val)
				} else {
					this.$emit('confirm')
				}
				if (this.beforeClose) return
				this.popup.close()
			},
			/**
			 * 点击取消按钮
			 */
			closeDialog() {
				this.$emit('close')
				if (this.beforeClose) return
				this.popup.close()
			},
			close() {
				this.popup.close()
			}
		}
	}
</script>


<style lang="scss">
	.classify-liv {
		text-align: center;
		align-items: center;
		padding-bottom: 10rpx;
		border: solid 2rpx #FD9A01;
		text-align: center;
		color: #999;
		border-radius: 10rpx;
		width: 200rpx;
		font-size: 24upx;
		margin: 10;

	}

	.classify-lixzlv {
		text-align: center;
		align-items: center;
		padding-bottom: 10rpx;
		border: solid 2rpx #999;

		color: #999;
		border-radius: 10rpx;
		width: 200rpx;
		font-size: 24upx;
		margin: 10;

	}

	.uni-popup-dialog {
		width: 300px;
		border-radius: 11px;
		background-color: #fff;
	}

	.uni-dialog-title {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		padding-top: 25px;
	}

	.uni-dialog-title-text {
		font-size: 16px;
		font-weight: 500;
	}

	.uni-dialog-content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		align-items: center;
		padding-top: 10rpx;
	}

	.uni-dialog-content-text {
		font-size: 14px;
		color: #6C6C6C;
	}

	.f20 {
		font-size: 24rpx;
	}

	.uni-dialog-button-group {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		border-top-color: #f5f5f5;
		border-top-style: solid;
		border-top-width: 1px;
	}

	.uni-dialog-button {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */

		flex: 1;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		height: 45px;
	}

	.uni-border-left {
		border-left-color: #f0f0f0;
		border-left-style: solid;
		border-left-width: 1px;
	}

	.uni-dialog-button-text {
		font-size: 16px;
		color: #333;
	}

	.uni-button-color {
		color: #007aff;
	}

	.uni-dialog-input {
		flex: 1;
		font-size: 14px;
		border: 1px #eee solid;
		height: 40px;
		padding: 0 10px;
		border-radius: 5px;
		color: #555;
	}

	.uni-popup__success {
		color: #4cd964;
	}

	.uni-popup__warn {
		color: #f0ad4e;
	}

	.uni-popup__error {
		color: #dd524d;
	}

	.uni-popup__info {
		color: #909399;
	}
</style>